package Paper;

import java.util.Random;

/*
    随机生成六个1-10（包含10）之间的数存入数组中
    然后计算出去掉最大值与最小值的平均数
 */
public class Code01 {
    public static void main(String[] args) {
        int length = 6;
        double avg;//调试后,int精度损失太多
        Random r = new Random();

        int[] arr = new int[length];
        arr[0] = r.nextInt(10) + 1;
        int max = arr[0];
        int min = arr[0];
        int sum = arr[0];
        for (int i = 1; i < length; i++) {
            arr[i] = r.nextInt(10) + 1;
            if (arr[i] > max){
                max = arr[i];
            }else if (arr[i] < min){
                min = arr[i];
            }
            sum += arr[i];
        }

        System.out.print("数组为:");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
        System.out.println("最大值为:"+max);
        System.out.println("最小值为:"+min);
        avg = (sum - max - min) / (length - 2.0);
        System.out.println("去掉最大最小后平均数为:"+avg);

    }
}
